package com.dreamchaser.familydevice.service.impl;

import com.alibaba.fastjson.JSON;
import com.dreamchaser.familydevice.util.QYWeChat.WeChatUtil;
import com.dreamchaser.familydevice.util.QYWeChat.service.IwxHandle;
import com.dreamchaser.familydevice.util.QYWeChat.service.WechatPush;
import com.dreamchaser.familydevice.util.device.ByteBufUtil;
import com.dreamchaser.familydevice.util.device.DeviceDataUtil;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/***
 * @author: SJun
 * @Date: 2020/8/13 17:11
 * @description:
 *
 */
@Component
@Slf4j
public class WxDeviceHandle implements IwxHandle {

    @Autowired
    WeChatUtil weChatUtil;
//    @Autowired
    //Function device;

    @Override
    public void run(WechatPush wechatPush) {
        log.info(JSON.toJSONString(wechatPush));
        int[] data = new int[1];
        Channel channel=null;
        switch (wechatPush.eventKey) {
            case "1": //次卧

                data[0] = 0x10;
                DeviceDataUtil.send(1,data);
                //Device1Handle.isStart = true;
                break;
            case "2": //走廊
                //channel = device.getChannel(2);
                data[0] = 0x10;
                DeviceDataUtil.send(2,data);
                //Device1Handle.isStart = true;
                break;
            case "3": //主卧
                //channel = device.getChannel(3);
                data[0] = 0x10;
                DeviceDataUtil.send(3,data);
                //Device1Handle.isStart = true;
                break;
            case "0": //关闭所有灯
                data[0] = 0x10;
                //device.send(1, data);
                //device.send(2, data);
                //device.send(3, data);
                break;
            case "ff": //获取所有状态
                data[0] = 0xff;
                //device.send(1, data);
                //device.send(2, data);
                //device.send(3, data);
                break;
        }
        log.info("消息已发送");
    }
}
